# -*- coding: utf-8 -*-
import json

from i_util.pymysql import PyMySQL 
import i_configurator.conf as conf


def mysql_conn():
    conn = PyMySQL(host=conf.mysql_host, post=conf.mysql_port, username=conf.username, password=conf.password, database=conf.database)
    return conn

def get_proxy():
    """
    Returns:{0:{'http': 'http://%s:%s@%s:%s'}, 1:{'http': 'http://%s:%s'},....}
    """
    try:
        conn = mysql_conn()
        sql = "select `value` from settings where item = 'proxy'"
        data = conn.fetch(sql)
        if not data:
            return {}
        data_list = json.loads(data[0])
        if not data_list:
            return {}
        return data_list
    except Exception as e:
        print "load proxy failed", e
        return {}
        pass
